var SEARCH_SMS_SEND_TYPE = 1;
var SEARCH_SMS_SENDDATE_END = 2; //建单开始时间
var SEARCH_SMS_SENDDATE_START = 4; //建单结束时间
$(document).ready(function() {
	initSearchData();
});

function buildSearchOptions(searchType, newdata) {
	var data = [{
		"name": "短信类型",
		"type": "TYPE",
		"className": "easyui-combobox",
		"id": "input_TYPE"
	}, {
		"name": "发送开始时间",
		"type": "SENDDATE_START",
		"className": "easyui-datebox",
		"id": "search_senddate_start"
	}, {
		"name": "发送结束时间",
		"type": "SENDDATE_END",
		"className": "easyui-datebox",
		"id": "search_senddate_end"
	}, ];
	var content = "";
	var s;
	for(var i = 0; i < data.length; i++) {
		s = searchType & (1 << i);
		if(s != 0) {
			content += "<td>" + data[i].name + "</td><td><input class=\"" + data[i].className + "\" name=\"" + data[i].type + "\" id=\"" + data[i].id + "\"/></td>";
		}
	}
	if(newdata.length > 0) {
		for(var i = 0; i < newdata.length; i++) {
			content += "<td>" + newdata[i].name + "</td><td><input class=\"" + newdata[i].className + "\" name=\"" + newdata[i].type + "\" id=\"" + newdata[i].id + "\"/></td>";
		}
	}
	var contain = "<div id=\"p\" class=\"easyui-panel\" title=\"查询\" style=\"width:100%;height:100%;\"><table cellspacing=\"4\" style=\"margin-top: 10px;\"><tr>" + content;
	contain += "<td><a href=\"#\" class=\"easyui-linkbutton\" onclick=\"doSearch()\" data-options=\"iconCls:'icon-search'\" style=\"width:80px;\">查询</a></td></tr></table></div>";
	return contain;
}

function initSearchData() {
	if($("#input_TYPE") != undefined) {
		$("#input_TYPE").combobox({
			panelHeight: 'auto',
			valueField: 'id',
			textField: 'text',
			data: [{
				"text": "生日短信",
				"id": "0",
				"group": "定时短信",
			}, {
				"text": "合同短信",
				"id": "1",
				"group": "定时短信",
			}, {
				"text": "群发短信",
				"id": "2",
				"group": "即时短信",
			}, {
				"text": "即时发送",
				"id": "3",
				"group": "即时短信",
			}, ]
		});
	}
}

function processSearchCondition() {
	if($("#div_search") == undefined) {
		console.log("请检查ID为div_search是否存在");
		return "";
	}
	var searchCondition = "";
	$("#div_search input[name]").each(function(index) {
		if($(this).val().trim().length != 0) {
			if(searchCondition == "") {
				searchCondition = $(this).attr("name") + "=" + $(this).val().trim();
			} else {
				searchCondition += "&" + $(this).attr("name") + "=" + $(this).val().trim();
			}
		}
	});
	return searchCondition;
}